
def addSearchFilters(request):
    execcode = []
    table = request.params.get('search_table_name')
    fields = dict((k,v) for (k,v) in request.params.items() if k.find('search_field_') == 0 and v.strip())
    for key, value in fields.items():
        fieldname, action = key.replace('search_field_', '').split('_')
        code = {
                'equal': lambda p_table,p_field,p_value: 'query=query.filter(%s.%s == "%s")' % (p_table,p_field,p_value),
                'like': lambda p_table,p_field,p_value: 'query=query.filter(%s.%s.like("%%%s%%"))' % (p_table,p_field,p_value),
        }[action](table, fieldname, value)
        execcode.append(code)
    return execcode, fields
